package com.wxp.controller.mall;

import java.text.SimpleDateFormat;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.wxp.controller.BaseController;
import com.wxp.service.ConstructionService;
import com.wxp.service.FullLoadService;
import com.wxp.service.MaterialService;
import com.wxp.util.IData;

@Controller
@RequestMapping(value = "/fullload")
public class FullLoadController extends BaseController {
	
	@Autowired
	private FullLoadService fullLoadService;

	@RequestMapping(value = "/realTimeFullLoad")
	@ResponseBody
	public Object fetchStatisticDate() throws Exception {
		IData pd = IData.getInstance(request);
		
		List<IData> datas = fullLoadService.realTimeFullLoad(pd);
		
		return datas;
	}
	
	@RequestMapping(value = "/fullLoadTrend")
	@ResponseBody
	public Object fullLoadTrend() throws Exception {
		IData pd = IData.getInstance(request);
		
		List<IData> datas = fullLoadService.fullLoadTrend(pd);
		
		return datas;
	}
	
	@RequestMapping(value = "/fullLoadTrendHis")
	@ResponseBody
	public Object fullLoadTrendHis() throws Exception {
		IData pd = IData.getInstance(request);
		
		List<IData> datas = fullLoadService.fullLoadTrendHis(pd);
		
		return datas;
	}
	
	@RequestMapping(value = "/sectionRank")
	@ResponseBody
	public Object sectionRank() throws Exception {
		IData pd = IData.getInstance(request);
		
		List<IData> datas = fullLoadService.sectionRank(pd);
		
		for(IData iData:datas) {
			if(iData.get("sectionName").toString().contains("黄陂南路")) {
				iData.put("sectionName", "一大会址●黄陂南路");
			}
			if(iData.get("sectionName").toString().contains("新天地")) {
				iData.put("sectionName", "一大会址●新天地");
			}
		}
		
		return datas;
	}
	
	@RequestMapping(value = "/loadHeader")
	@ResponseBody
	public Object loadHeader() throws Exception {
		IData pd = IData.getInstance(request);
		
		List<IData> datas = fullLoadService.loadHeader(pd);
		
		return datas;
	}
	
	@RequestMapping(value = "/loadSectionFullLoadTrend")
	@ResponseBody
	public Object loadSectionFullLoadTrend() throws Exception {
		IData pd = IData.getInstance(request);
		
		List<IData> datas = fullLoadService.loadSectionFullLoadTrend(pd);
		
		return datas;
	}
	
	@RequestMapping(value = "/loadMaxSectionFullLoad")
	@ResponseBody
	public Object loadMaxSectionFullLoad() throws Exception {
		IData pd = IData.getInstance(request);
		
		List<IData> datas = fullLoadService.loadMaxSectionFullLoad(pd);
		
		return datas;
	}
	
	@RequestMapping(value = "/loadLineFullLoadTopEight")
	@ResponseBody
	public Object loadLineFullLoadTopEight() throws Exception {
		IData pd = IData.getInstance(request);
		
		List<IData> datas = fullLoadService.loadLineFullLoadTopEight(pd);
		
		return datas;
	}
	
	@RequestMapping(value = "/loadLineFullLoadBottomSeven")
	@ResponseBody
	public Object loadLineFullLoadBottomSeven() throws Exception {
		IData pd = IData.getInstance(request);
		
		List<IData> datas = fullLoadService.loadLineFullLoadBottomSeven(pd);
		
		return datas;
	}
	
	//查询早晚高峰满载率最高线路
	@RequestMapping(value = "/loadPeakFullload")
	@ResponseBody
	public Object loadPeakFullload() throws Exception {
		IData pd = IData.getInstance(request);
		
		List<IData> datas = fullLoadService.loadPeakFullload(pd);

		return datas;
	}
	
	//查询昨日满载率最高区间
	@RequestMapping(value = "/loadTopFullloadSection")
	@ResponseBody
	public Object loadTopFullloadSection() throws Exception {
		IData pd = IData.getInstance(request);
		
		List<IData> datas = fullLoadService.loadTopFullloadSection(pd);
		
		for(IData iData:datas) {
			if(iData.get("sectionName").toString().contains("黄陂南路")) {
				iData.put("sectionName", "一大会址●黄陂南路");
			}
			if(iData.get("sectionName").toString().contains("新天地")) {
				iData.put("sectionName",  "一大会址●新天地");
			}
		}
		
		return datas;
	}
	
	//查询线路上下行满载率
	@RequestMapping(value = "/loadUpDownFullloadData")
	@ResponseBody
	public Object loadUpDownFullloadData() throws Exception {
		IData pd = IData.getInstance(request);
		
		String lineId = pd.getString("lineId");
		if(!StringUtils.isEmpty(lineId) && lineId.length()<=1) {
			pd.put("lineId","0"+lineId);
		}
		List<IData> datas = fullLoadService.loadUpDownFullloadData(pd);
		for(IData iData:datas) {
			if(iData.get("sectionName").toString().contains("黄陂南路")) {
				iData.put("sectionName", "一大会址●黄陂南路");
			}
			if(iData.get("sectionName").toString().contains("新天地")) {
				iData.put("sectionName", "一大会址●新天地");
			}
		}
		
		
		return datas;
	}
	
	
	
	
}
